﻿@model Epi.Web.MVC.Models.FormResponseInfoModel
<div id="formtitle" class="formtitle">
    <h2 class="surveyTitle" style="line-height: 120%; display:none;">
        @Model.FormInfoModel.FormName
    </h2>
    <div id="NumberOfRecords" class="NumberOfRecords">
        <div>
            @{
                if (Model.NumberOfPages == 0)
                {
                    <span class="boldlabel">0 Records </span>
                }
                else
                {
                    @*<span >Showing</span>*@
                    <span class="boldlabel">
                        @(
                        Model.CurrentPage * Model.PageSize - (Model.PageSize - 1))
                        -
                        @if (Model.CurrentPage * Model.PageSize < Model.NumberOfResponses)
                        {
                            @(Model.CurrentPage * Model.PageSize)
                        }
                        else
                        {
                            @Model.NumberOfResponses
                        }
                    </span>
                    <span>of </span><span class="boldlabel">
                        @Model.NumberOfResponses
                    </span>
                }
            }
        </div>
    </div>

</div>
<script>
    $(document).ready(function () {
        
        $("#btnsearch").click(function () {
            $("#searchbox").toggle();
        });
        if ($("#SHOW_GRID").val() == "true") {
        

            ReadLinkResponses($("#LinkFormId_HIDDEN_0").val(), '@Session["PageNumber"]', '', '', '@Session["FromResponseId"]');
            $("#FROM_RESPONSEID_HIDDEN").val('@Session["FromResponseId"]');
            $('#@Session["FromResponseId"]').closest("tr").addClass("TrSelected");
        }
        
    

    });
    //$(document).live("click", ".ClickableRow tr", function (e) {
    $('.ClickableRow  tr').click(function (e) {

        ResetSearchFields();
        var RecordId = $(this).find("[name='EditForm']").val();
        //alert($("#LinkFormId_HIDDEN_0").val());
        $(this).addClass("TrSelected").siblings().removeClass("TrSelected");
         
        ReadLinkResponses($("#LinkFormId_HIDDEN_0").val(), '@Session["PageNumber"]', '', '', RecordId);
        $("#FROM_RESPONSEID_HIDDEN").val(RecordId);
    });
    function ShowCasesOnly()
    {

        $('#FormLink').hide();

    }
    function ShowContacts() {
        $('#FormLink').show();

    }
</script>
<div id="editsettings" class="editsettings">
    <button type="submit" name="AddNewFormId" class="default record" value="@Model.FormInfoModel.FormId">Add New Record</button>

    @if (Model.FormInfoModel.IsSQLProject)
    {
        <span>&nbsp;&nbsp;</span>
        <button id="btnsearch" onclick="" class="default search" type="button">Search</button>
    }
    @if (Model.FormInfoModel.IsOwner)
    {
        <span>&nbsp;&nbsp;</span>
        <button id="btneditsettings" onclick="GetSettings()" class="default settings" type="button">Settings</button>
    }
</div>
<div style="clear: both"></div>

<div id="searchbox" style="display: none;">
    <div class="searchrow">       
            @Html.DropDownListFor(m => m.SearchModel.SearchCol1, Model.SearchColumns1, string.Empty)
            @Html.TextBoxFor(m => m.SearchModel.Value1, string.Empty)
    </div>
    <div class="searchrow">  
        @Html.DropDownListFor(m => m.SearchModel.SearchCol2, Model.SearchColumns2, string.Empty)
        @Html.TextBoxFor(m => m.SearchModel.Value2, string.Empty)
    </div>
    <div class="searchrow">     
            @Html.DropDownListFor(m => m.SearchModel.SearchCol3, Model.SearchColumns3, string.Empty)
            @Html.TextBoxFor(m => m.SearchModel.Value3, string.Empty)
    </div>
    <div class="searchrow">
            @Html.DropDownListFor(m => m.SearchModel.SearchCol4, Model.SearchColumns4, string.Empty)
            @Html.TextBoxFor(m => m.SearchModel.Value4, string.Empty)
    </div>
    <div class="searchrow" style="display: inline-block; margin-right: 15px;">
            @Html.DropDownListFor(m => m.SearchModel.SearchCol5, Model.SearchColumns5, string.Empty)
            @Html.TextBoxFor(m => m.SearchModel.Value5, string.Empty)
    </div>
    <button class="default" name="Search">Go</button>
    <button class="default" name="ResetSearch">Reset</button>
</div>
@{
    WebGrid webGrid = new WebGrid(rowsPerPage: 20,
        canSort: false, canPage: false, ajaxUpdateContainerId: "recordstable"); // Model.SurveyAnswerResponse.pageSize
    webGrid.Bind(Model.ResponsesList, autoSortAndPage: false, rowCount: Model.NumberOfResponses); //Model.SurveyAnswerResponse.pageSize * Model.ResponsesList.Count TBD
}
<div id="recordscontent" class="recordscontent">   
    <div style="clear: both; margin-bottom: 10px; padding: 0px 0 0;">
        @if (Model.FormInfoModel.IsSQLProject && Model.SearchModel.SearchCol1 != null)
        {
            <div id="searchmsg" style="display:block; background:#ffdead; padding:5px 5px 9px; color:#794800; margin: 2px 0 15px 0;">
                <span>
                    Only showing records matching your search criteria. &nbsp;&nbsp;&nbsp;
                    <button class="default" name="ResetSearch" style="float:right;">Reset Search</button>
                </span>
            </div>
        }
        
        <div style="position:relative; margin-top: 5px;">
            @if (Model.FormInfoModel.IsSQLProject)
            {
                <div id="tableSort" class="tableSort" style="vertical-align: middle;">
                    <select id="columns" style="width: 172px;">
                        @foreach (var item in Model.Columns)
                        {
                            if (@item.Value.ToString() == @Model.sortfield)
                            {
                                <option value="@item.Value.ToString()" selected=selected>@item.Value.ToString()</option>
                            }
                            else
                            {
                                <option value="@item.Value.ToString()">@item.Value.ToString()</option>
                            }
                        }
                    </select>
                    <button id="SortASC" class="default" style="padding:0 8px; vertical-align: top; height:24px; ">
                        <img src="~/Content/images/Sort-Ascending.png" style="width: 13px; vertical-align: middle;" />
                    </button>
                    <button id="SortDESC" class="default" style="padding:0 8px; vertical-align: top; height:24px;">
                        <img src="~/Content/images/Sort-Descending.png" style="width: 13px; vertical-align: middle;" />
                    </button>
                    
                    @*<button id="btncaseonly" onclick="ShowCasesOnly();" class="default" type="button" style="margin-left:30px; height:24px; vertical-align: top;">Show Cases Only</button>
                    <button id="btncontact" onclick="ShowContacts();" class="default" type="button" style="height:24px; vertical-align: top;">Show Contacts</button>*@
                    
                </div>
            }
            <div id="paging" class="paging" style="margin-top: 6px;">
                @{

                    if (Model.NumberOfPages > 1)
                    {
                        <div id="pager" class="pager">
                            @Html.Partial("PagerPartial", Model)
                        </div>
                    }


                }
            </div>
            <div style="clear: both; margin-bottom: 15px;"></div>
        </div>
     
        <div id="recordstable" class="recordstable">
                @{
                    var gridColumns = new List<WebGridColumn>();
                   
                    
                    gridColumns.Add(webGrid.Column(header: "",
                        format: (item) => new HtmlString("<button name='EditForm' type='submit'  class='default edit'  id='" + item.Column0 + "'value='" + item.Column0 + "/" + Model.FormInfoModel.FormId + "'>Open</button>")));
                    if (Model.Columns.Count >= 1)
                    {
                        gridColumns.Add(webGrid.Column("Column1", (Model.Columns.Count >= 1) ? Model.Columns[0].Value : ""));
                    }
                    if (Model.Columns.Count >= 2)
                    {
                        gridColumns.Add(webGrid.Column("Column2", (Model.Columns.Count >= 2) ? Model.Columns[1].Value : ""));
                    }
                    if (Model.Columns.Count >= 3)
                    {
                        gridColumns.Add(webGrid.Column("Column3", (Model.Columns.Count >= 3) ? Model.Columns[2].Value : ""));
                    }
                    if (Model.Columns.Count >= 4)
                    {
                        gridColumns.Add(webGrid.Column("Column4", (Model.Columns.Count >= 4) ? Model.Columns[3].Value : ""));
                    }
                    if (Model.Columns.Count >= 5)
                    {
                        gridColumns.Add(webGrid.Column("Column5", (Model.Columns.Count >= 5) ? Model.Columns[4].Value : ""));
                    }
                    if(Model.FormInfoModel.HasLink){
                          @webGrid.GetHtml(columns: gridColumns, tableStyle: "ClickableRow");
                         }
                         else
                         {
                    
                           @webGrid.GetHtml(columns: gridColumns);
                        }
                }
            @if (Model.FormInfoModel.HasLink)
            {
                <input id="SHOW_GRID" type="hidden" value="true" />
            }
            else
            {
                <input id="SHOW_GRID" type="hidden" value="false" />

            }
                @Html.Hidden("hidFormId", @Model.FormInfoModel.FormId)
                @Html.Hidden("hidPageNumber", @Model.CurrentPage)
                @{
                    if (Model.NumberOfPages == 0)
                    {
                        <div class="zerorec">
                            No records found.
                        </div>
                    }
                }
            </div>
           

           

           

           
     </div>
</div>

@*  <script type="text/javascript">
    var formId =  document.getElementById('hidFormId').value; //$('#hidFormId').val();
    var pageId = $('#hidPageNumber').val();
        var returnUrl = 'returnUrl=' + formId + '/' + pageId;
        var redirectTimeout = @FormsAuthentication.Timeout.TotalMilliseconds
        var redirectTimeoutHandle = setTimeout(function() { window.location.href = '@FormsAuthentication.LoginUrl' + '?'+ returnUrl; }, redirectTimeout);
    </script>*@
